﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Drawables;
using GameEngine.SceneGraph;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Redland2
{
    public class Entity : Sprite
    {
        #region members
            private Vector2 _velocity = Vector2.Zero;
            public List<Entity> _collisions = new List<Entity>();
            public GameScene scene;
            public int index;
            private bool alive;
            public string type = "entity";
            public Random rand;
            private Player _owner;
        #endregion members

        #region properties
            /// <summary>
            /// Gets/Sets the X component of the _velocity vector.
            /// </summary>
            public float XVelocity
            {
                get { return _velocity.X; }
                set { _velocity.X = value; }
            }

            /// <summary>
            /// Gets/Sets the Y component of the _velocity vector.
            /// </summary>
            public float YVelocity
            {
                get { return _velocity.Y; }
                set { _velocity.Y = value; }
            }

            public Vector2 Velocity
            {
                get { return _velocity; }
                set { _velocity = value; }
            }

            public Player Owner
            {
                get { return _owner; }
                set { _owner = value; }
            }

            public bool IsAlive()
            {
                return alive;
            }
        #endregion properties

        #region constructors
            public Entity(GameScene inputScene, int inputIndex, Texture2D texture, Vector2 position ) : base(texture, position)
            {
                rand = new Random(inputScene._time.Milliseconds);
                scene = inputScene;
                index = inputIndex;
                alive = true;
                Scene.Current.Drawables.Add(this);
            }
        #endregion construcors

        #region methods
            public override void Update(GameTime gameTime)
            {
                if (_collisions.Count > 0)
                {
                    HandleCollision();
                }
                this.Position += _velocity;
                base.Update(gameTime);
            }

            public virtual bool offscreen()
            {
                if (this.Position.X > 0 && this.Position.Y > 0 && this.Position.X < 1280 && this.Position.Y < 700)
                    return false;
                return true;
            }

            public virtual void HandleCollision()
            {                
                _collisions.RemoveRange(0,_collisions.Count);
            }

            public virtual void Kill()
            {
                this.alive = false;
            }

            public virtual void Hide()
            {
                this.Visible = false;
            }


        #endregion methods
    }
}
